<template>
	<view class="person-file">
		<bs-navbar title='个人档案'></bs-navbar>
		<bsSearch ref='bsSearch' @handScreen='handScreen' @search='search' :leftShow='false'></bsSearch>
		<view class="file-box">
			<bsPersonFileList :status='status' :list='personFileList' @handDateils='handDateils'></bsPersonFileList>
		</view>
		<screenPopup @handReset='handReset' @handSubType='handSubType' ref='screenPopup'></screenPopup>
		<u-back-top :scroll-top="scrollTop"></u-back-top>
	</view>
</template>

<script>
	import bsSearch from '@/components/bs-search/bs-search.vue'
	import bsPersonFileList from '@/components/bs-person-file-list/bs-person-file-list.vue'
	import screenPopup from './components/screenPopup.vue'
	export default {
		components: {
			bsSearch,
			bsPersonFileList,
			screenPopup
		},
		data() {
			return {
				status: 'nomore',
				searchForm: {
					recordName: '',
					shoolName: '',
				},
				pages: 0,
				personFileList: [],

				paging: {
					page: 1,
					pageSize: 10,
					type: 0,
				},
				scrollTop: 0

			};
		},
		onPageScroll(e) {
			this.scrollTop = e.scrollTop;
		},
		async onPullDownRefresh() {
			for (let key in this.searchForm) {
				this.searchForm[key] = ''
			}
			this.$refs.screenPopup.typeList.forEach(item => {
				item.flg = false
			})
			await this.init()
			uni.stopPullDownRefresh();
		},
		async onReachBottom() {
			await this.getMore()
		},
		async mounted() {
			await this.init()
		},
		methods: {
			async handReset() {
				this.$refs.screenPopup.typeList.forEach(item => {
					item.flg = false
				})
				this.$refs.bsSearch.keyword = ''
				for (let key in this.searchForm) {
					this.searchForm[key] = ''
				}
				await this.init()
				uni.showToast({
					title: '重置成功',
					icon: 'none'
				})
				this.$refs.screenPopup.hide()
			},
			//类别搜索
			async handSubType(shoolObj) {
				if (shoolObj) {
					this.searchForm.shoolName = shoolObj.name
					await this.init()
					this.$refs.screenPopup.hide()
				} else {
					uni.showToast({
						title: '请选择',
						icon: 'none'
					})
				}
			},
			//关键字搜索
			async search() {
				console.log('???')
				this.searchForm.recordName = this.$refs.bsSearch.keyword
				await this.init()
			},
			async getMore() {
				if (this.pages == this.paging.page) {
					this.status = 'nomore';
					return
				}
				this.status = 'loading';
				this.paging.page = ++this.paging.page;
				let personFileList = await this.$u.api.selectRecordList({
					...this.paging,
					...this.searchForm
				})
				this.pages = personFileList.pages
				this.personFileList = this.personFileList.concat(personFileList.list)
				this.status = 'loadmore';
			},
			async init() {
				this.status = 'loading';
				this.paging.page = 1
				this.paging.type = 0
				let personFileList = await this.$u.api.selectRecordList({
					...this.paging,
					...this.searchForm
				})
				this.pages = personFileList.pages
				this.personFileList = personFileList.list
				if (this.pages == this.paging.page) {
					this.status = 'nomore';
				}
				console.log(this.personFileList, '个人档案')

			},
			handScreen() {
				this.$refs.screenPopup.open()
			},
			handDateils(item) {
				uni.navigateTo({
					url: '/pages/personFile/personFileDetails/personFileDetails?recordId=' + item.recordId
				})
			}
		}
	}
</script>

<style lang="scss">
	page {
		background-color: $bs-bg-color-grey;
	}

	.person-file {
		background-color: $bs-bg-color-grey;
		height: 100%;

		.file-box {
			padding: 0 30rpx;
			padding-top: 40rpx;
		}

		.file-list {
			.item {
				padding: 40rpx 30rpx;
				background: #FFFFFF;
				box-shadow: 0 0 26px 0 rgba(18, 27, 83, 0.07);
				border-radius: $bs-border-radius-12;
				margin-bottom: 30rpx;

				.cont {
					@include ellipsisMultiline(3)
				}
			}

			.type {
				margin-top: 14rpx;
				margin-bottom: 20rpx;
				color: $bs-text-color-999;
				font-size: $bs-font-size-24;
			}
		}
	}
</style>
